export const mixin = {
  data() {
    return {
      // dataArr: [],
      dataArr: [],
      loading: false,
      bottomLine: false,
      pageIndex: 1,
      showloading: false
    }
  },
  created() {
    // console.log(this.isActive);
    this.inint()
  },
  methods: {
    loadTop() {
      this.inint()
      this.$refs.loadmore.onTopLoaded();
    },
    ajaxBefore() {
      this.loading = true
      this.showloading = true
    },
    ajaxNoData() {
      this.loading = true
      this.showloading = false
      this.bottomLine = true

    },
    ajaxErr() {
      this.loading = true
      this.showloading = false
      this.bottomLine = false
    },
    ajaxAllDataFinish(totalNum) {
      if (this.pageIndex * 10 >= totalNum) {
        //alert("加载完毕")
        this.bottomLine = true
        this.loading = true
      } else {
        // alert("还有数据")
        this.loading = false
      }
      this.showloading = false
      this.pageIndex++
    },
    loadMore() {
      if (this.loading == false) {
        let url = `/job/Load?pageIndex=${this.pageIndex}&docStatus=${this.docStatus}&pageSize=10&jobType=1`
        // alert('又触发loadMore')
        this.ajaxBefore()
        axios.get(url)
          .then(res => {
            if (res.data.Data.data.toString()) {
              this.dataArr = this.dataArr.concat(res.data.Data.data)
              this.ajaxAllDataFinish(res.data.Data.totalCount)
            } else {
              this.ajaxNoData()
            }
          })
          .catch(err => {
            this.ajaxErr()
          })
      }
    },
    cancelOrder(item, status, index) {
      let that = this
      let ccc = weui.confirm('是否取消订单', {
        title: '提示',
        buttons: [{
          label: '否',
          type: 'default',
          onClick: function () {
            console.log('no')
          }
        }, {
          label: '是',
          type: 'primary',
          onClick: function () {
            ccc.hide(function () {
              let url = `/job/update?docNo=${item.DocNo}&documentStatus=10`
              axios.post(url)
                .then(res => {
                  if (res.data.IsSuccess) {
                    weui.toast('取消成功', 1000);
                    that.deletArr(index)
                  } else {
                    weui.alert(res.data.Msg)
                  }
                  // 打印成功
                })
                .catch(err => {})
            })
          }
        }]
      });
    },
    getFile(item, status, index) {
      let that = this
      let Mode =  sessionStorage.getItem("Mode")
      if (Mode === 'Free') {
        that.upData(item, status, index)
      } 
      // c端
      else {
        sessionStorage.setItem('DocNo' , item.DocNo)
        sessionStorage.setItem('fromWay','pick')
        that.$router.push('/setting')
      }
    },
    upData(item, status, index) {
      let that = this
      const url = `${this.$url}/job/update?docNo=${item.DocNo}&documentStatus=${status}`
      this.$axios.post(url)
        .then(res => {
          if (res.data.IsSuccess) {
            weui.toast('取件成功', 1000)
            this.updataView(index)
          } else {
            weui.alert(red.data.Msg)
          }
          // 打印成功
        })
        .catch(err => {

        })
    },
    deletArr(index) {
      let shadowDataArr = Array.from(this.dataArr)
      shadowDataArr.splice(index, 1)
      this.dataArr = shadowDataArr
    },
    inint() {
      // 因为数据是共享的 所以重新初始化一遍
      this.loading = false,
      this.bottomLine = false,
      this.pageIndex = 1,
      this.showloading = false
      let url = `/job/Load?pageIndex=1&docStatus=${this.docStatus}&pageSize=10&jobType=1`
      this.ajaxBefore()
      axios.get(url)
        .then(res => {
          if (res.data.Data.toString()) {
            this.dataArr = res.data.Data.data
            // 判断是不是所有数据加载完毕
            this.ajaxAllDataFinish(res.data.Data.totalCount)
          } else {
            this.ajaxNoData()
          }
        })
        .catch(err => {
          this.ajaxErr()
        })
    },
    gotoPrint() {
      this.$router.push('./print')
    },


  }
}
export default mixin
